// 📁 service/NotificationService.java
package com.library.management.service;

import com.library.management.entity.Notification;
import com.library.management.entity.User;
import com.library.management.enums.NotificationPriority;
import com.library.management.enums.NotificationType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
/**
 * 通知服务接口
 * 处理通知消息相关的业务逻辑
 */
public interface NotificationService extends BaseService<Notification, Long> {

    /**
     * 根据用户查找通知
     */
    List<Notification> findByUser(User user);

    /**
     * 根据用户ID查找通知
     */
    List<Notification> findByUserId(Long userId);

    /**
     * 根据阅读状态查找通知
     */
    List<Notification> findByIsRead(Boolean isRead);

    /**
     * 查找未读通知
     */
    List<Notification> findUnreadNotifications();

    /**
     * 查找用户的未读通知
     */
    List<Notification> findUnreadNotificationsByUserId(Long userId);

    /**
     * 根据通知类型查找通知
     */
    List<Notification> findByType(NotificationType type);

    /**
     * 根据优先级查找通知
     */
    List<Notification> findByPriority(NotificationPriority priority);

    /**
     * 查找有效的通知（未过期）
     */
    List<Notification> findValidNotifications();

    /**
     * 查找已过期的通知
     */
    List<Notification> findExpiredNotifications();

    /**
     * 查找紧急通知（高优先级且未读）
     */
    List<Notification> findUrgentNotifications();

    /**
     * 统计用户的未读通知数量
     */
    long countUnreadByUserId(Long userId);

    /**
     * 标记通知为已读
     */
    Notification markAsRead(Long notificationId);

    /**
     * 批量标记通知为已读
     */
    void markMultipleAsRead(List<Long> notificationIds);

    /**
     * 标记所有用户通知为已读
     */
    void markAllAsReadByUserId(Long userId);

    /**
     * 发送系统通知
     */
    Notification sendSystemNotification(User user, String title, String content,
                                        NotificationPriority priority, LocalDateTime expireTime);

    /**
     * 发送借阅通知
     */
    Notification sendBorrowNotification(User user, String title, String content,
                                        Long relatedId, LocalDateTime expireTime);

    /**
     * 发送归还通知
     */
    Notification sendReturnNotification(User user, String title, String content,
                                        Long relatedId, LocalDateTime expireTime);

    /**
     * 发送逾期通知
     */
    Notification sendOverdueNotification(User user, String title, String content,
                                         Long relatedId, LocalDateTime expireTime);

    /**
     * 发送预约通知
     */
    Notification sendReservationNotification(User user, String title, String content,
                                             Long relatedId, LocalDateTime expireTime);

    /**
     * 批量发送通知
     */
    List<Notification> sendBatchNotifications(List<User> users, String title, String content,
                                              NotificationType type, NotificationPriority priority,
                                              LocalDateTime expireTime);

    /**
     * 删除过期通知
     */
    void deleteExpiredNotifications();

    /**
     * 分页查询用户的通知
     */
    Page<Notification> findByUserId(Long userId, Pageable pageable);

    /**
     * 分页查询用户的未读通知
     */
    Page<Notification> findUnreadByUserId(Long userId, Pageable pageable);

    /**
     * 根据关联业务信息查找通知
     */
    List<Notification> findByRelatedInfo(Long relatedId, String relatedType);
}